package LinkedList;

public class _138_CopyListwithRandomPointer {
    //ignore circle situation
    public RandomListNode copyRandomList(RandomListNode head) {
        if(head==null) return null;
        RandomListNode start = new RandomListNode(head.label);
        RandomListNode p = head,begin = start;
        if (p.next == null && p.random != null) {
            start.random = new RandomListNode(p.random.label);
        }
        while (p.next!= null) {
            start.next = new RandomListNode(p.next.label);
            if (p.random != null) {
                start.random = new RandomListNode(p.random.label);
            }
            start = start.next;
            p = p.next;
        }
        if (p.random != null) {
            start.random = new RandomListNode(p.random.label);
        }
        return begin;
    }
}
